<?php

class TqqUserController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';
	
	
	public function beforeAction($action){
		if(Yii::app()->user->isGuest&&$action->getId()!='login'){
			//$this->redirect(Yii::app()->loginUrl);
			echo "123";
		}
		return parent::beforeAction($action);
	}
	
	/**
	 * @return array action filters
	 */
	public function filters()
	{	
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view','oauth','test','save'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{
		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
	}

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new TqqUser;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['TqqUser']))
		{
			$model->attributes=$_POST['TqqUser'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}

	/**
	 * Updates a particular model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param integer $id the ID of the model to be updated
	 */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['TqqUser']))
		{
			$model->attributes=$_POST['TqqUser'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		if(Yii::app()->request->isPostRequest)
		{
			// we only allow deletion via POST request
			$this->loadModel($id)->delete();

			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if(!isset($_GET['ajax']))
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}

	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$dataProvider=new CActiveDataProvider('TqqUser');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new TqqUser('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['TqqUser']))
			$model->attributes=$_GET['TqqUser'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=TqqUser::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='tqq-user-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
	
	
	
	public function actionOauth($appName) {
		
		$oOAuth = new TOAuth(Yii::app()->params[$appName]['oauth_consumer_key'], Yii::app()->params[$appName]['oauth_consumer_secret']);

		if(isset($_GET["oauth_token"])&&$_GET["oauth_verifier"]) {//授权第二步
		
			$aParam = array(
					"oauth_token" => $_GET["oauth_token"],
					"oauth_verifier" => $_GET["oauth_verifier"],
			);
		
			$oOAuth->setToken($aParam["oauth_token"],Yii::app()->session["oauth_token_secret"]);
			$sURL =  TOAuth::$oauth_access_token;
			$sReturn = $oOAuth->send($aParam, $sURL);
			parse_str($sReturn, $aReturn);
			//在session储存以备使用
			//print_r($aReturn);exit;
			Yii::app()->session["uname"] = $aReturn["name"];
			Yii::app()->session["oauth_token"] = $aReturn["oauth_token"];
			Yii::app()->session["oauth_token_secret"] =  $aReturn["oauth_token_secret"];
			Yii::app()->session["openid"] = $_GET["openid"];
			Yii::app()->session["openkey"] =  $_GET["openkey"];
			Yii::app()->session["appName"] = $appName;
			
			$this->redirect(array('save','appName'=>$appName));
			
			
		} else {//授权第一步
			
			$aParam = array(
					"oauth_callback" => Yii::app()->params['oauth_callback'],
			);
			$sURL = TOAuth::$oauth_request_token;
			$sReturn = $oOAuth->send($aParam, $sURL);
			parse_str($sReturn, $aReturn);
			Yii::app()->session["oauth_token_secret"] = $aReturn["oauth_token_secret"];  //保存oauth_token_secret
			$sRedirect =  TOAuth::$oauth_authorize."?oauth_token=".$aReturn["oauth_token"];
			header("Location:".$sRedirect);
		
		}

	}
	
	public function actionTest() {
		/*
		$oOAuth = new TOAuth(Yii::app()->params['oauth_consumer_key'], Yii::app()->params['oauth_consumer_secret']);

		$ot = Yii::app()->session["oauth_token"];
		$ots = Yii::app()->session["oauth_token_secret"];
		
		$oOAuth->setToken($ot,$ots);
		$aParam = array(
				"format" => "json",
		);
		$sURL = "http://open.t.qq.com/api/user/info";
		$sReturn = $oOAuth->send($aParam, $sURL, "GET");
		$aReturn = json_decode($sReturn, TRUE);
			
		if(isset($aReturn['ret'])&&$aReturn['ret']==0) {
		
			echo '</br>OAuth call_result:</br><pre>';
			print_r($aReturn);
			echo '</pre>';
			echo '</br>=====================================================</br>';
		
		}*/
		/*echo Yii::app()->params['bottle']['oauth_consumer_key'];
		
		$str="iVBORw0KGgoAAAANSUhEUgAAAlgAAABDCAYAAABA6HutAAAUmElEQVR4Xu2d2Z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Lt6SJN7EBEzABEzABFQC2es0RhRV+8Qmrv6Xe3ujfe2hfsn9NQfdlnyLwMpsRf5Dgnci8hgfLVuXT/Z/Z/wUxeQeJ4yPFxdGaGfxu9uNGPu5CZiACZiACRwTQF8u35tn1aSQqNqNRK+lupuMqrmyazKwVIGCznZTzGXiUxXDnfhEZ4/7Z/FQ3cqdzGUZd/FhgcVEv8eYgAmYgAlcI9B9YR19b4n5XtJ+87D+f3VjgoTSujVhb1zW+E4IKCCZ/+KSZYLETGZXJo6Q/dUr4HiDtPuJPUO19+Rsyv7dq85T2xFPPzcBEzABEzABioAbEoXJg0zABEzABEzABEyAJ2CBxbPySBMwARMwARMwAROgCFhgUZg8yARMwARMwARMwAR4AhZYPCuPNAETMAETMAETMAGKgAUWhcmDTMAETMAETMAETIAnYIHFs/JIEzABEzABEzABE6AIWGBRmDzIBEzABEzABEzABHgCFlg8K480ARMwARMwARMwAYrAvwDMww7LcxJubgAAAABJRU5ErkJggg==";
		echo base64_decode($str);*/
		
		/*
		 * 
		 * Yii framework已经定义的命名空间常量
			system: 指向Yii框架目录; YII\framework
			zii: 指向zii library 目录; YII\framework\zii
		 * 
		 * application : 指向应用程序基本目录;  protected\
			webroot: 指向包含里入口脚本 文件的目录. 此别名自 1.0.3 版起生效. \
			ext : 指向包含所有第三方扩展的目录, 从版本 1.0.8 可用;  \protected\extensions
		 * 
		 * 
		 * */
		//YII framework路径
		echo Yii::getFrameworkPath();
	
		echo Yii::app()->getRuntimePath(); //运行时环境  protected/runtime
		
		Yii::import('application.venders.*'); // 导入某些类，可以在main中默认导入
		//插入 meta 信息
		Yii::app()->clientScript->registerMetaTag('keywords','关键字');
		Yii::app()->clientScript->registerMetaTag('description','一些描述');
		Yii::app()->clientScript->registerMetaTag('author','作者');
		Yii::app()->clientScript->registerMetaTag(' text/html;charset=utf-8', null, 'Content-Type');
		
		//<link rel="alternate" type="application/rss+xml" href="http://www.dreamdu.com/feed/" />

		Yii::app()->clientScript->registerLinkTag('alternate','application/rss+xml',$this->createUrl('/feed'));
		
		// 插件 js 和 css  
		
		Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');
		Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');
		
		
		//调用YII框架中framework/web/js/source的js,
		//其中registerCoreScript key调用的文件
		//在framework/web/js/packages.php列表中可以查看
		
		
		//Yii 实现数据库读写分离
		
		/***** 方式一、实例添加 *****/
		$session=new CHttpSession;
		$session->open();
		$value1=$session['name1'];
		
		/***** 方式二、直接调用应用添加 *****/
		Yii::app()->session->add('name','foobar');
		Yii::app()->session->add('name2','foobar');
		Yii::app()->session->add('name3','foobar');
		//或者
		$session = Yii::app()->session;
		$session['key'] = 'value';
		var_dump($session['key']);
		 
		//遍历
		foreach($session as $name=>$value) {
			echo  $name."<-->".$value;
		};
		
		//当前时间存入 session 避免短时间多次提交
		
		
		// 设置一个cookie
		$cookie=new CHttpCookie($name,$value);
		Yii::app()->request->cookies[$name]=$cookie;
		
		
		// 检索一个名为$name的cookie值
		$cookie=Yii::app()->request->cookies[$name];
		echo $value=$cookie->value;
	
		
		
		//php缓存 需要 php_apc.dll
		
		
	}
	
	public function actionSave($appName) {
		//保存用户数据
		$flag = false;
		$user = new TqqUser;
		$user->uname = Yii::app()->session["uname"];
		$user->appkey = Yii::app()->params[$appName]['oauth_consumer_key'];
		$user->ot = Yii::app()->session["oauth_token"];
		$user->ots  = Yii::app()->session["oauth_token_secret"];
		$user->openid = Yii::app()->session["openid"];
		$user->openkey = Yii::app()->session["openkey"];
		$user->info = "0";
		$user->otime = time();
		$tempUser= $user->findByAttributes(array('appkey'=>$user->appkey,'uname'=>$user->uname));
		
		if($tempUser!=NULL) {
			$flag = $tempUser->updateAll(array('ot'=>$user->ot,'ots'=>$user->ot,'otime'=>$user->otime),
					'appkey=:appkey and uname=:uname',
					array(':appkey'=>$user->appkey,':uname'=>$user->uname)); 
		} else {
			$flag = $user->save();
		}
	
		
		if($flag==true) {
			$this->render('save',array(
					'user'=>$user,
				));
				
		} else {
			throw new CHttpException(400,'update data error.');
		}
		
		
		
		
		
	}
	
}
